#ifndef _SMSROUTER_H
#define _SMSROUTER_H

#include "queue.h"

#include <glib.h>
#include <semaphore.h>
#include <time.h>

#define MAX_FILTER_LEN 128
#define MAX_SENDER_NAME_LEN 128
#define MAX_PASSWORD_LEN 128
#define MAX_SN_LEN 20
#define NET_BUF_LEN 1024
#define QUEUE_MAX_LEN 512


typedef enum
{
    PACKET_TYPE_SMS_NORMAL,
    PACKET_TYPE_SMS_GROUP, // group send with same message
} PACKET_TYPES;


typedef struct
{
    int packet_size;
} SMS_PACKET_HEADER;


typedef struct
{
    PACKET_TYPES type; // normal or gourp 
    char *cell_phone_number;
    char * message;
} SMS_TASK;


DECLARE_QUEUE_TYPE(Sender, SMS_TASK, QUEUE_MAX_LEN)


typedef struct sender_parameter
{
    char name[MAX_SENDER_NAME_LEN];
	 char sn[MAX_SN_LEN];
    char password[MAX_PASSWORD_LEN];
    char filter_string[MAX_FILTER_LEN];
    struct timespec sema_spec;
    pthread_mutex_t out_queue_lock;
    MKSSenderQueue out_queue;
    sem_t *out_queue_sema;
    GRegex *filter;
    GTimer *timer;
    gboolean (* status)(gchar *, gchar *);

    gint (* send_message)(gchar *,  // sn
                          gchar *,  // password
                          SMS_TASK *); // message
    // send *SAME* message to a group of numbers
    gint (* send_grouped_messages)(gchar *,  // sn 
                                   gchar *,  // password
                                   gchar *,  // phone numbers sepereated by ,
                                   gchar *); // message

    // sende *INDIVIDUAL* messages to a group of numbers
    gint (* send_grouped_individual_messages)(gchar *,    // sn
                                              gchar *,    // password
                                              gchar *,    // phone numbers sepereated by ','
                                              gchar *);  // messages seperated by ','
} SENDER_PARAMETER;


typedef struct receiver_parameter
{
    int cli_sockfd;    
    GPtrArray *senders;
} RECEIVER_PARAMETER;


SENDER_PARAMETER *sender_para_init();
void *recv_thread(void *new_server_socket);
void *send_thread(void *parameters);


#endif
